<?php
namespace Admin\Controller;

class LoginController extends BaseController
{
    public function login()
    {
        if (IS_POST) { //判断是否是post请求 is_post  is_get is_ajax
            $username = I('post.username');
            $password = encrypt_password(I('post.password'));

            $res = m('admin')->where(array('username' => $username, 'password' => $password))->find();

            if(!empty($res)){
                //查询用户对于的权限值
                $level = M("admin")->join("__GROUP__ ON __ADMIN__.level = __GROUP__.id")->where("tp_admin.id=". $res["id"])->getField("tp_group.level");

                $level = json_decode($level);
                //将用户名存储到session中

                session('username',$username);
                //将密码存储到session中
                session('password',$password);
                session('level',$level);

            $a=I('post.online',NULL);
                if(isset($a)){
                //将用户名密码存储到cookie中
                cookie('username',$username,C('cookie_time'));
                cookie('password',$password,C('cookie_time'));
                cookie("level",$level);
                }



                $this->redirect('index/index');
                
            }else{
                $this->error('登陆失败',u("login/login"));
                die;


            }
        }


        //$this->display();//没跨控制器没跨操作 则就默认加载当前模块view文件中当前控制器下的当前操做
        $this->assign();
        $this->display();//加载当前模块view文件中news控制器下的news.html*/
        }


}